package sjtu.ist.warehouse4ws.dao.cust;

import java.util.List;

import org.hibernate.SQLQuery;

import sjtu.ist.warehouse4ws.dao.BaseDaoHibernate;
import sjtu.ist.warehouse4ws.model.CustColumnValue;

public class CustColumnValueDaoHibernate extends BaseDaoHibernate<CustColumnValue> implements CustColumnValueDao {
	public void createTable(String custName){
		String sql="CREATE TABLE `"+custName+"_cust_column_value` ("
			+"`id` int(32) NOT NULL,"
			+"`columnId` int(32) DEFAULT NULL,"
			+"`value` varchar(150) DEFAULT NULL,"
			+"PRIMARY KEY (`id`)"
			+")";
		SQLQuery query=getSession().createSQLQuery(sql);
		query.executeUpdate();
	}

	@Override
	public List<CustColumnValue> getByTable(String tablename) {
		// TODO Auto-generated method stub
		return getHibernateTemplate().find("from CustColumnValue v where v.columnId in (select c.id from CustColumn c where c.tablename='"+tablename+"')");
	}
}
